package adv5;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

//1 :baidu:找出HashTable的特点，比较HashTable和HashMap的差异;
//分别加入10万个数，比较时间。再随机删除  100个数，比较时间
public class Work {
    public static void main(String[] args) {
        Map<Integer, Integer> hashTable = new Hashtable<>();
        Map<Integer, Integer> hashMap = new HashMap<>();
        long l1 = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            hashTable.put(i, 2);
        }
        long l2 = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            hashTable.put(i, 2);
        }
        long l3 = System.nanoTime();
        System.out.println("增加：");
        System.out.println("hashtable:" + (l2 - l1) + "ns");
        System.out.println("hashmap:" + (l3 - l2) + "ns");
        long l4 = System.nanoTime();
        for (int i = 0; i < 100; i++) {
            int s = (int) (Math.random() * 1000000);
            hashTable.remove(s);
        }
        long l5 = System.nanoTime();
        for (int i = 0; i < 100; i++) {
            int s = (int) (Math.random() * 1000000);
            hashTable.remove(s);
        }
        long l6 = System.nanoTime();
        System.out.println("删除：");
        System.out.println("hashtable:" + (l5 - l4) + "ns");
        System.out.println("hashmap:" + (l6 - l5) + "ns");
    }
}